package com.khyr.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.khyr.entity.HealthPatientResult;
import com.khyr.entity.HealthTestDetail;
import com.khyr.entity.HealthTestList;
import com.khyr.entity.HisPatient;
import com.khyr.feign.UserFeign;
import com.khyr.service.HealthService;
import com.khyr.vo.GetTestResultVo;
import com.khyr.vo.R;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：Zhang
 * @date ：Created in 2025/3/18 20:27
 * @description：健康测试
 * @modified By：
 * @version: 1.0
 */
@RestController
@RequestMapping("/health/healthAll")
public class HealthController {
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private UserFeign userFeign;
    @Autowired
    private HealthService healthService;
    /**
     * @create by: Zr
     * @description: 获取所有的健康测试的信息
     * @create time: 2025/3/18 20:46
     * @param
     * @return com.khyr.vo.R<java.util.List<com.khyr.entity.HealthTestList>>
     */
    @GetMapping("/getAllHealthTest")
    public R<List<HealthTestList>> getAllHealthTest(){
        return healthService.getAllHealthTest();
    }
    /**
     * @create by: Zr
     * @description: 根据健康测试的主键id查询健康测试的详情（题目）
     * @create time: 2025/3/18 20:55
     * @param htId
     * @return com.khyr.vo.R<java.util.List<com.khyr.entity.HealthTestDetail>>
     */
    @GetMapping("/getTestDetailById/{htId}")
    public R<List<HealthTestDetail>> getHealthTestById(@PathVariable String htId){
        return healthService.getHealthTestById(htId);
    }
    /**
     * @create by: Zr
     * @description: 抑郁测试结果 or 情商（EQ）测试结果
     * @create time: 2025/3/19 11:16
     * @param healthTestDetails
     * @return com.khyr.vo.R<com.khyr.vo.GetTestResultDto>
     */
    @PostMapping("/getTestResult")
    public R<GetTestResultVo> getTestResult(@RequestBody List<HealthTestDetail> healthTestDetails){
        String token = request.getHeader("token");
        // 获取当前登录者的信息
        HisPatient patient=userFeign.getPatientInfo(token).getData();
        System.out.println("patient = " + patient);
        return healthService.getTestResult(healthTestDetails,patient);
    }
    /**
     * @create by: Zr
     * @description: FPA性格色彩测试结果
     * @create time: 2025/3/19 11:17
     * @param healthTestDetails
     * @return com.khyr.vo.R<com.khyr.vo.GetTestResultDto>
     */
    @PostMapping("/getTestResult02")
    public R<GetTestResultVo> getTestResult02(@RequestBody List<HealthTestDetail> healthTestDetails){
        String token = request.getHeader("token");
        // 获取当前登录者的信息
        HisPatient patient=userFeign.getPatientInfo(token).getData();
        return healthService.getTestResultFPA(healthTestDetails,patient);
    }
    @GetMapping("/getTestHistory")
    public R<Page<HealthPatientResult>> getTestHistory(Integer current, Integer size){
        String token = request.getHeader("token");
        // 获取当前登录者的信息
        HisPatient patient=userFeign.getPatientInfo(token).getData();
        return healthService.getTestHistory(patient,current,size);
    }
}
